package com.ruoyi.system.controller.car4s_controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.car4s_domain.Car4sCustomerInfo;
import com.ruoyi.system.service.car4s_service.ICar4sCustomerInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 客户信息Controller
 * 
 * @author LK
 * @date 2024-06-29
 */
@RestController
@RequestMapping("/system/car_4s_customer_info")
public class Car4sCustomerInfoController extends BaseController
{
    @Autowired
    private ICar4sCustomerInfoService car4sCustomerInfoService;

    /**
     * 查询客户信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:car_4s_customer_info:list')")
    @GetMapping("/list")
    public TableDataInfo list(Car4sCustomerInfo car4sCustomerInfo)
    {
        startPage();
        List<Car4sCustomerInfo> list = car4sCustomerInfoService.selectCar4sCustomerInfoList(car4sCustomerInfo);
        return getDataTable(list);
    }

    /**
     * 导出客户信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:car_4s_customer_info:export')")
    @Log(title = "客户信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Car4sCustomerInfo car4sCustomerInfo)
    {
        List<Car4sCustomerInfo> list = car4sCustomerInfoService.selectCar4sCustomerInfoList(car4sCustomerInfo);
        ExcelUtil<Car4sCustomerInfo> util = new ExcelUtil<Car4sCustomerInfo>(Car4sCustomerInfo.class);
        util.exportExcel(response, list, "客户信息数据");
    }

    /**
     * 获取客户信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:car_4s_customer_info:query')")
    @GetMapping(value = "/{customerId}")
    public AjaxResult getInfo(@PathVariable("customerId") Long customerId)
    {
        return success(car4sCustomerInfoService.selectCar4sCustomerInfoByCustomerId(customerId));
    }

    /**
     * 获取客户信息详细信息  byPhone
     */
    @PreAuthorize("@ss.hasPermi('system:car_4s_customer_info:query')")
    @GetMapping(value = "/getInfoByPhoneNum/{phoneNum}")
    public AjaxResult getInfoByPhoneNum(@PathVariable("phoneNum") String phoneNum)
    {
        return success(car4sCustomerInfoService.selectCar4sCustomerInfoByPhoneNum(phoneNum));
    }


    /**
     * 新增客户信息
     */
    @PreAuthorize("@ss.hasPermi('system:car_4s_customer_info:add')")
    @Log(title = "客户信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Car4sCustomerInfo car4sCustomerInfo)
    {
        return toAjax(car4sCustomerInfoService.insertCar4sCustomerInfo(car4sCustomerInfo));
    }

    /**
     * 修改客户信息
     */
    @PreAuthorize("@ss.hasPermi('system:car_4s_customer_info:edit')")
    @Log(title = "客户信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Car4sCustomerInfo car4sCustomerInfo)
    {
        return toAjax(car4sCustomerInfoService.updateCar4sCustomerInfo(car4sCustomerInfo));
    }

    /**
     * 删除客户信息
     */
    @PreAuthorize("@ss.hasPermi('system:car_4s_customer_info:remove')")
    @Log(title = "客户信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{customerIds}")
    public AjaxResult remove(@PathVariable Long[] customerIds)
    {
        return toAjax(car4sCustomerInfoService.deleteCar4sCustomerInfoByCustomerIds(customerIds));
    }
}
